package com.wn.mine.view

import androidx.activity.OnBackPressedCallback
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.wn.common.base.BaseFragment
import com.wn.mine.R
import com.wn.mine.databinding.FragmentMineInfoBinding

/**
 * @Author: wn
 * @Date: 2023/5/12 16:38
 * @Description: 个人中心--用户信息界面
 */
class MineInfoFragment : BaseFragment<FragmentMineInfoBinding>() {
  //  委托方式  获取 args <当前类名+Args>
  private val args by navArgs<MineInfoFragmentArgs>()

  override fun getLayoutRes() = R.layout.fragment_mine_info
  override fun initView() {
    super.initView()
    mBinding.apply {

      // 传递 databinding 数据
      data = args.info

      // toolbar返回上个界面
      mineInfoToolbar.mtoolbarLogin.setNavigationOnClickListener {
        findNavController().navigateUp()
      }
      // app:defaultNavHost="true" 不生效  这里 直接拦截 返回键
      requireActivity().onBackPressedDispatcher.addCallback(this@MineInfoFragment, object :
        OnBackPressedCallback(true) {
        override fun handleOnBackPressed() {
          findNavController().navigateUp()// 返回上一级 fragment
//        requireActivity().finish()// 直接退出 activity
        }
      })
    }
  }

}